package com.atguigu.gulimall.order.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

import com.atguigu.gulimall.order.entity.OrderReturnApplyEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.gulimall.order.entity.OrderItemEntity;
import com.atguigu.gulimall.order.service.OrderItemService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;



/**
 * 订单项信息
 *
 * @author wuweiji557
 * @email wuweiji557@gmail.com
 * @date 2024-11-07 23:12:23
 */
@RestController
@RequestMapping("order/orderitem")
public class OrderItemController {
    @Autowired
    private OrderItemService orderItemService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //RequiresPermissions("order:orderitem:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderItemService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("order:orderitem:info")
    public R info(@PathVariable("id") Long id){
		OrderItemEntity orderItem = orderItemService.getById(id);

        return R.ok().put("orderItem", orderItem);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("order:orderitem:save")
    public R save(@RequestBody OrderItemEntity orderItem){
		orderItemService.save(orderItem);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:orderitem:update")
    public R update(@RequestBody OrderItemEntity orderItem){
		orderItemService.updateById(orderItem);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:orderitem:delete")
    public R delete(@RequestBody Long[] ids){
		orderItemService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     *
     * @param message
     * @param entity
     * @param channel
     *//*
    @RabbitListener(queues = {"hello-java-queue"})
    public void recieveMessage(Message message, OrderReturnApplyEntity entity, Channel channel) {
        byte[] body = message.getBody();
        MessageProperties messageProperties = message.getMessageProperties();

        System.out.println("订单服务接收到消息：" + message+"-->内容"+entity);
        long deliveryTag = messageProperties.getDeliveryTag();
        //messageProperties.getDeliveryTag() 是消息的唯一标识符，用于确认消息已经被处理,按顺序自增
        System.out.println("messageProperties.getDeliveryTag()：" + deliveryTag);
        //手动签收货物
        try{
            if(deliveryTag%2==0){
                channel.basicAck(deliveryTag,false);
                System.out.println("签收了货物:"+deliveryTag);
            }else {
                //channel.basicNack:退货 requeue=false 丢弃 requeue=true 发回服务器，服务器重新入队。
                channel.basicNack(deliveryTag,false,true);
                System.out.println("未签收货物:"+deliveryTag);
            }

        }catch (Exception e){}

    }*/
}
